<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of NetworkController
 *
 * @author mateusz.ledzewicz
 */
class ChartsController extends Controller {
    protected $id;
    protected function begin() {
        $this->view = new ViewCharts();
        if(isSet($_GET['id_test']) && !empty($_GET['id_test']))
        {
             $this->view->setVar('id-test', $_GET['id_test']);
        } 
        if(isSet($_GET['id_train']) && !empty($_GET['id_train']))
        {
           $this->view->setVar('id-train', $_GET['id_train']); 
        } 
        
       
    }
    
    protected function run() {
        
        $type = (isSet($_GET[ConfigInput::actionGet])) ? $_GET[ConfigInput::actionGet] : null;
        switch($type){
            case 'value':
                $this->valueRun();
            break;
            case 'test':
               $this->testRun();
            break;
            case 'train':
               $this->trainRun();
            break;
            case 'error':
               $this->errorRun();
            break;
            default:
                //$this->infoRun();
            break; 
        }
    }

 
    protected function valueRun()
    {
        if(isSet($_GET['id_test'])){
           
           $id = $_GET['id_test'];
           $array = ChartData::getData($id, ChartData::DataTest, 30);
           $title = ' testowych';
       } else if (isSet($_GET['id_train'])){
           $id = $_GET['id_train'];
           $array = ChartData::getData($id, ChartData::DataTrain, 30);
           $title = ' treningowych';
          
       }
        $data = ChartData::prepareChartString($array);
       $this->view->setVar('chartDataHeader', "['Date', 'Value'],");
       $this->view -> setVar('chartData',$data);
       
       $this->view->setVar('chartTitle', 'Wykres wartości w czasie około danych'.$title);
        
    }
    protected function trainRun()
    {
        if(!isSet($_GET['id_train']))
            Throw new Exception ("Bad id_train");
        
        $id = $_GET['id_train'];
        $array = Data_network::getTwoValues($id, Data_network::typeCompare);
        $data = ChartData::prepareChartString($array);
        $this->view->setVar('chartDataHeader', "['In', 'Train output', 'Network output'],");
        $this->view -> setVar('chartData', $data);
        $this->view->setVar('chartTitle', 'Wykres danych treningowych i wyników sieci');
        
    }
    
    protected function testRun()
    {
        if(!isSet($_GET['id_test']))
            Throw new Exception ("Bad id_test");
        
        $id = $_GET['id_test'];
        $array = Data_test::getTwoValues($id, Data_test::typeCompare);
        $data = ChartData::prepareChartString($array);
        $this->view->setVar('chartDataHeader', "['In', 'Test output', 'Network output'],");
        $this->view -> setVar('chartData', $data);
       $this->view->setVar('chartTitle', 'Wykres danych testowych i wyników sieci');
       
       
       
    }
    
    
    protected function errorTestRun()
    {
       
       
       $test = Test::loadModel($this->id, array('Test_data'));
       $chartData = new ChartData($test->id_test, $test->id_test_data->id_test_data, ChartData::DataTest);
       $this->view->setVar('chartDataHeader', "['In', 'Error'],");
       $this->view -> setVar('chartData', $chartData->getChartNetworkError());
       $this->view->setVar('chartTitle', 'Wykres błędu na danych testowych');
       
       
       
    }
    
    protected function errorRun()
    {
       $array = array();
       $title = '';
       if(isSet($_GET['id_test'])){
           
           $id = $_GET['id_test'];
           $array = Data_test::getOneValues($id, Data_test::typeError);
           $title = ' testowych';
       } else if (isSet($_GET['id_train'])){
           
           $id = $_GET['id_train'];
           
           $array = Data_network::getOneValues($id, Data_network::typeError);
           $title = ' treningowych';
          
       }
      
       $data = ChartData::prepareChartString($array);
        
      
       $this->view->setVar('chartDataHeader', "['In', 'Error'],");
       $this->view -> setVar('chartData', $data);
       $this->view->setVar('chartTitle', 'Wykres błędu na danych'.$title);
       
       
       
    }

    //put your code here
}

?>
